using FreeSql.DataAnnotations;
using SumerCoreDevOps.Shared.Enums;

namespace SumerCoreDevOps.Domain.Entities;

/// <summary>
/// 工作流阶段
/// </summary>
[Table(Name = "stages")]
[Index("idx_workflow", nameof(WorkflowDefinitionId), false)]
public class Stage
{
    [Column(IsPrimary = true, IsIdentity = true)]
    public long Id { get; set; }

    /// <summary>
    /// 工作流定义ID
    /// </summary>
    public long WorkflowDefinitionId { get; set; }

    /// <summary>
    /// 阶段名称
    /// </summary>
    [Column(StringLength = 200)]
    public string Name { get; set; } = null!;

    /// <summary>
    /// 执行顺序
    /// </summary>
    public int Order { get; set; }

    /// <summary>
    /// 执行模式（串行/并行）
    /// </summary>
    public ExecutionMode ExecutionMode { get; set; } = ExecutionMode.Serial;

    /// <summary>
    /// 触发条件（JSON格式）
    /// </summary>
    [Column(StringLength = -1)]
    public string? TriggerCondition { get; set; }

    /// <summary>
    /// 创建时间
    /// </summary>
    public DateTime CreatedAt { get; set; } = DateTime.UtcNow;

    /// <summary>
    /// 工作流定义
    /// </summary>
    [Navigate(nameof(WorkflowDefinitionId))]
    public WorkflowDefinition WorkflowDefinition { get; set; } = null!;

    /// <summary>
    /// 步骤列表
    /// </summary>
    [Navigate(nameof(Step.StageId))]
    public List<Step> Steps { get; set; } = [];
}
